//
//  YWSDKUtil.m
//  faceTime
//
//  Created by 历成栋 on 2020/11/26.
//
#define APP_YW_Secret "xr0pg6q4"
#define APP_YW_Id "7biy1jeu29"

#define APP_YM_Token "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJRCI6IjdiaXkxamV1MjkiLCJleHAiOjE2MDY1NzQ3MDAsInNhbHQiOiI4RDdtTmd2c1ZKam5USCJ9.EsYfN8D34A4Q0irgYAn3qYFT2gASR0DXmEC8odgezLk"

#import "YWSDKUtil.h"
#import "PathUtil.h"
#import "YWHelper.h"
@interface YWSDKUtil ()<YWHelperDelegate,CloudroomVideoMgrCallBack>

@end

@implementation YWSDKUtil

+ (BOOL)initYWSDK{
    if ([[CloudroomVideoSDK shareInstance] isInitSuccess]) {
        [[CloudroomVideoSDK shareInstance] uninit];
    }
    SdkInitDat *initDat = [[SdkInitDat alloc] init];
    [initDat setSdkDatSavePath:[PathUtil searchPathInCacheDir:@"YWSDKDatSavePath"]];
    [initDat setShowSDKLogConsole:YES];
    [initDat setTimeOut:60000];
    CRVIDEOSDK_ERR_DEF  error = [[CloudroomVideoSDK shareInstance] initSDK:initDat];
    if (error!=CRVIDEOSDK_NOERR) {
        [[CloudroomVideoSDK shareInstance] uninit];
        return NO;
    }
    return YES;
}

+(void)uninitYESDK{
    if ([[CloudroomVideoSDK shareInstance] isInitSuccess]) {
        [[CloudroomVideoSDK shareInstance] uninit];
    }
}

+(void)setServerAddress:(NSString *)address{
    [[CloudroomVideoSDK shareInstance] setServerAddr:address];
}

-(void)setYWMgrCallback:(id<CloudroomVideoMgrCallBack>)callBack{
    [[CloudroomVideoMgr shareInstance] setMgrCallback:callBack];
}

-(void)removeYWMgrCallback:(id<CloudroomVideoMgrCallBack>)callBack{
    [[CloudroomVideoMgr shareInstance] removeMgrCallback:callBack];
}

-(void)YWLoginByToken{
    [[YWHelper shareInstance] readYWLoginInfoResultsDelegate:self];
}

- (void)readYWLoginInfoResultsIsSuccess:(BOOL)isSuccess{
    if (isSuccess==NO) {
        DLog(@"网络请求失败");
    }else {
        [self setYWMgrCallback:self];
        [[CloudroomVideoMgr shareInstance] loginByToken:[YWHelper shareInstance].ywToken nickName:[YWHelper shareInstance].ywnickName userID:[YWHelper shareInstance].ywUserId userAuthCode:[YWHelper shareInstance].ywUserAuthCode cookie:[YWHelper shareInstance].ywCookie];
    }
}

-(void)loginSuccess:(NSString *)usrID cookie:(NSString *)cookie{
    DLog(@"登录成功");
}

-(void)loginFail:(CRVIDEOSDK_ERR_DEF)sdkErr cookie:(NSString *)cookie{
    DLog(@"登录失败");
}

- (void)lineOff:(CRVIDEOSDK_ERR_DEF)sdkErr{
    DLog(@"断开链接🔗");
}

- (void)YWSDKLogout{
    DLog(@"注销登录");
    [self removeYWMgrCallback:self];
    [[CloudroomVideoMgr shareInstance] logout];
}


-(void)ywCreateMeeting:(NSString *)meetSubject createPswd:(BOOL)createPswd cookie:(NSString *)cookie{
    [[CloudroomVideoMgr shareInstance] createMeeting:meetSubject createPswd:createPswd cookie:cookie];
}


-(void)createMeetingSuccess:(MeetInfo *)meetInfo cookie:(NSString *)cookie{
    
}

-(void)createMeetingFail:(CRVIDEOSDK_ERR_DEF)sdkErr cookie:(NSString *)cookie{
    
}

-(void)destroyMeetingRslt:(CRVIDEOSDK_ERR_DEF)sdkErr cookie:(NSString *)cookie{
    
}



@end
